#include "vv_log.h"
#include "VVLog.h"
#include <stdarg.h>

VVLOGHANDLE vv_log_create(const char *log_path, const char *log_module, VV_LOG_LEVEL level)
{
    VVLog* log = new VVLog(log_path, log_module, level);
    return log;
}

void vv_log_destroy(VVLOGHANDLE handle)
{
    VVLog* log = (VVLog*)handle;
    delete log;
}

void vv_log_trace(VVLOGHANDLE handle, const char *fmt, ...)
{
    if (!handle)
        return;
    VVLog* log = (VVLog*)handle;
    va_list args;
    va_start(args, fmt);
    log->trace(fmt, args);
    va_end(args);
}

void vv_log_debug(VVLOGHANDLE handle, const char *fmt, ...)
{
    if (!handle)
        return;
    VVLog* log = (VVLog*)handle;
    va_list args;
    va_start(args, fmt);
    log->debug(fmt, args);
    va_end(args);
}

void vv_log_info(VVLOGHANDLE handle, const char *fmt, ...)
{
    if (!handle)
        return;
    VVLog* log = (VVLog*)handle;
    va_list args;
    va_start(args, fmt);
    log->info(fmt, args);
    va_end(args);
}

void vv_log_warn(VVLOGHANDLE handle, const char *fmt, ...)
{
    if (!handle)
        return;
    VVLog* log = (VVLog*)handle;
    va_list args;
    va_start(args, fmt);
    log->warn(fmt, args);
    va_end(args);
}

void vv_log_error(VVLOGHANDLE handle, const char *fmt, ...)
{
    if (!handle)
        return;
    VVLog* log = (VVLog*)handle;
    va_list args;
    va_start(args, fmt);
    log->error(fmt, args);
    va_end(args);
}

void vv_log_critical(VVLOGHANDLE handle, const char *fmt, ...)
{
    if (!handle)
        return;
    VVLog* log = (VVLog*)handle;
    va_list args;
    va_start(args, fmt);
    log->critical(fmt, args);
    va_end(args);
}

void vv_log_func(VVLOGHANDLE handle, VV_LOG_LEVEL level, const char *fmt, ...)
{
    if (!handle)
        return;
    VVLog* log = (VVLog*)handle;
    va_list args;
    va_start(args, fmt);
    switch(level) {
    case VV_LOG_TRACE:
        log->trace(fmt, args);
        break;
    case VV_LOG_DEBUG:
        log->debug(fmt, args);
        break;
    case VV_LOG_INFO:
        log->info(fmt, args);
        break;
    case VV_LOG_WARN:
        log->warn(fmt, args);
        break;
    case VV_LOG_ERROR:
        log->error(fmt, args);
        break;
    case VV_LOG_CRITICAL:
        log->critical(fmt, args);
        break;
    default:
        log->info(fmt, args);
        break;
    }
    va_end(args);
}
